﻿using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static DLLPC.Utilities.PointRotation;
using DLLPC.Utilities;

namespace VisionCore
{
    public class LoadInfoHelper
    {
        /// <summary>
        /// 列数
        /// </summary>
        private int col = 0;
        /// <summary>
        /// 行数
        /// </summary>
        private int row = 0;
        private PRM_FixtureInfo info;
        private Point[,] BasePoints;

        public LoadInfoHelper(PRM_FixtureInfo info)
        {
            this.info = info;
            col = info.ColSize;
            row = info.RowSize;
            BasePoints = new Point[row, col];

            UpdataAllTrayPos();
        }

        private void UpdataAllTrayPos()
        {
            for (int r = 0; r < row; r++)
            {
                for (int c = 0; c < col; c++)
                {
                    double dX = info.Base.x + ParameterHelper.SysParam.ULDSTBase.CCDPitch.X + (info.ColWidth * c) ;
                    double dY = info.Base.y - ParameterHelper.SysParam.ULDSTBase.CCDPitch.Y - (info.RowHeight * r) ;

                    BasePoints[r, c] = new PointRotation.Point(dX, dY);
                }
            }
        }

        public List<LoadInfo> CreateLoadRoad()
        {
            int loadIdx = 0;
            List<LoadInfo> roads = new List<LoadInfo>();

            for (int r = 0; r < row; r++)
            {
                for (int c = 0; c < col; c++)
                {
                    LoadInfo tempInfo = new LoadInfo();

                    int cIdx = 0;
                    if (r % 2 == 0)
                    {
                        cIdx = c;
                    }
                    else
                    {
                        cIdx = col - 1 - c;
                    }

                    tempInfo.Info.Base = BasePoints[r, cIdx];
                    tempInfo.Info.ColIdx = cIdx;
                    tempInfo.Info.RowIdx = r;
                    tempInfo.Info.PRM_ID = string.Format("{0}-{1}", r.ToString("d2"), cIdx.ToString("d2"));
                    tempInfo.LoadIdx = loadIdx;
                    tempInfo.CompFlag = false;

                    roads.Add(tempInfo);
                    loadIdx++;
                }
            }

            return roads;
        }
    }
}
